package com.ruoyi.storage.controller;

import java.util.List;

import com.ruoyi.common.utils.SecurityUtils;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.storage.domain.ItemDetail;
import com.ruoyi.storage.service.IItemDetailService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 库存详情Controller
 * 
 * @author ruoyi
 * @date 2025-01-11
 */
@RestController
@RequestMapping("/storage/warehouseDetail")
public class ItemDetailController extends BaseController
{
    @Autowired
    private IItemDetailService itemDetailService;

    /**
     * 查询库存详情列表
     */
    @PreAuthorize("@ss.hasPermi('storage:warehouseDetail:list')")
    @GetMapping("/list")
    public TableDataInfo list(ItemDetail itemDetail)
    {
        startPage();
        List<ItemDetail> list = itemDetailService.selectItemDetailList(itemDetail, SecurityUtils.getUserId());
        return getDataTable(list);
    }

    /**
     * 导出库存详情列表
     */
    @PreAuthorize("@ss.hasPermi('storage:warehouseDetail:export')")
    @Log(title = "库存详情", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ItemDetail itemDetail)
    {
        List<ItemDetail> list = itemDetailService.selectItemDetailList(itemDetail, SecurityUtils.getUserId());
        ExcelUtil<ItemDetail> util = new ExcelUtil<ItemDetail>(ItemDetail.class);
        util.exportExcel(response, list, "库存详情数据");
    }

    /**
     * 获取库存详情详细信息
     */
    @PreAuthorize("@ss.hasPermi('storage:warehouseDetail:query')")
    @GetMapping(value = "/{itemId}")
    public AjaxResult getInfo(@PathVariable("itemId") String itemId)
    {
        return success(itemDetailService.selectItemDetailByItemId(itemId));
    }

    /**
     * 新增库存详情
     */
    @PreAuthorize("@ss.hasPermi('storage:warehouseDetail:add')")
    @Log(title = "库存详情", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ItemDetail itemDetail)
    {
        return toAjax(itemDetailService.insertItemDetail(itemDetail));
    }

    /**
     * 修改库存详情
     */
    @PreAuthorize("@ss.hasPermi('storage:warehouseDetail:edit')")
    @Log(title = "库存详情", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ItemDetail itemDetail)
    {
        return toAjax(itemDetailService.updateItemDetail(itemDetail));
    }

    /**
     * 删除库存详情
     */
    @PreAuthorize("@ss.hasPermi('storage:warehouseDetail:remove')")
    @Log(title = "库存详情", businessType = BusinessType.DELETE)
	@DeleteMapping("/{itemIds}")
    public AjaxResult remove(@PathVariable String[] itemIds)
    {
        return toAjax(itemDetailService.deleteItemDetailByItemIds(itemIds));
    }

    /**
     * 配送入库新增库存详情
     */
    @PreAuthorize("@ss.hasPermi('storage:warehouseInventory:detail')")
    @Log(title = "库存详情", businessType = BusinessType.INSERT)
    @PostMapping("/addEntryDetail")
    public AjaxResult deliveryEntryAdd(@RequestBody List<ItemDetail> itemDetailList)
    {
        return toAjax(itemDetailService.deliveryEntryInsertItemDetailList(itemDetailList));
    }
}
